package com.service.component.group.controller;

import com.service.component.common.CommonResult;
import com.service.component.common.enumerate.OperateTypeEnum;
import com.service.component.group.entity.Group;
import com.service.component.group.services.GroupServices;
import com.service.component.log.aspect.SysOperateLog;
import com.service.component.relation.entity.GroupFilterPermRelation;
import com.service.component.relation.entity.GroupFilterRoleRelation;
import com.service.component.relation.entity.UserFilterPermRelation;
import com.service.component.relation.entity.UserGroupRelation;
import com.service.component.relation.services.RelationServices;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ：Administrator
 * @create ：2021/7/22 13:17
 * @description：组管理控制操作
 * @modified By：
 * @version: 1.0.0$
 */
@Slf4j
@RestController
@Api(value = "组管理")
@RequestMapping("/group")
public class GroupController {

    @Autowired
    private GroupServices groupServices;
    @Autowired
    private RelationServices relationServices;

    @PostMapping("insertGroup")
    public CommonResult insertGroup(@RequestBody Group group){
        return groupServices.insertGroup(group);
    }

    @PostMapping("insertUserGroup")
    public CommonResult insertUserGroup(@RequestBody UserGroupRelation userGroupRelation){
        return relationServices.insertOrUpdateRelation(userGroupRelation);
    }

    @ApiOperation(value = "新增或者修改组负权限", notes = "新增或者修改组负权限")
    @GetMapping(value = "insertGroupFilterPerm", produces = {"application/json;charset=UTF-8"})
    @SysOperateLog(descrption = "新增或者修改组负权限", operateType = OperateTypeEnum.ADD)
    public CommonResult insertGroupFilterPerm(@RequestBody GroupFilterPermRelation groupFilterPermRelation) {
        return relationServices.insertOrUpdateRelation(groupFilterPermRelation);
    }

    @ApiOperation(value = "新增或者修改用户负角色", notes = "新增或者修改用户负角色")
    @GetMapping(value = "insertGroupFilterRole", produces = {"application/json;charset=UTF-8"})
    @SysOperateLog(descrption = "新增或者修改用户负角色", operateType = OperateTypeEnum.ADD)
    public CommonResult insertGroupFilterRole(@RequestBody GroupFilterRoleRelation groupFilterRoleRelation) {
        return relationServices.insertOrUpdateRelation(groupFilterRoleRelation);
    }
}
